<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .dv_container {
            width: 350px;
            height: 400px;
            /* background-color: rebeccapurple; */
            margin: 0 auto;
        }

        .dv_container .dv {
            width: 100%;
            height: 150px;
            /* background-color: skyblue; */
        }

        .dv_container .dv div {
            width: 100px;
            height: 100px;
            background-color: black;
            float: left;
            margin: 0 5px;
        }
    </style>
</head>

<body>
    <div class="dv_container">
        <button onclick="onClickRed()">点击将div变成红色</button>
        <div class="dv">
            <div id="box"></div>
            <div id="box"></div>
            <div id="box"></div>
        </div>
    </div>
</body>
<script>
    var obox = document.getElementsByTagName("div");
    function onClickRed() {
        for (var i = 2; i < obox.length; i++) {
            console.log(obox.length);
            obox[i].style.background = "red";
        }
    }
</script>

</html>